package com.skyolder.milkbee.tool;

import java.util.ArrayList;

import com.skyolder.milkbee.domain.Category;
import com.skyolder.milkbee.dto.CategoryTreeItem;

public class WalkTree {
	public static CategoryTreeItem findParent(CategoryTreeItem tree,Long parentId){
		Category c=tree.getNode();
		if(c.getId()==parentId){
			return  tree;
		}
		ArrayList<CategoryTreeItem> list=tree.getChildren();
		if(list==null){
			return null;
		}
		for(CategoryTreeItem item:list){
			CategoryTreeItem rst=WalkTree.findParent(item, parentId);
			if(rst!=null){
				return rst;
			}
		}
		return null;
	}
}
